def set_stage():
""" Sets up the stage for the game """
stage.set_background("soccerfield")
stage.disable_floor()
def main():
""" Sets up the program and calls other functions """
set_stage()
main()
t = codesters.Teacher()
defs = t.find_block("def")
docstrings = t.find_text('"""')
num_docstrings = len(docstrings)
default_doc = '""" This is a description of what this function does """'.replace(' ','').lower()
ignore_defs = ['set_stage', 'main']
def get_above_def(line_number, def_list):
""" Returns the name of the nearest function and the distance above the given line number """
function_name = ""
distance = line_number - def_list[0][0]
for func in def_list:
if line_number - func[0] <= distance and line_number - func[0] > 0:
function_name = func[1]
distance = line_number - func[0]
return function_name, distance
def find_new_function(ignore_list, def_list):
""" Returns tuples of (line_number, function def) for any functions that aren't specified in ignore list """
return_list = []
for d in def_list:
count = 0
for i in ignore_list:
if i in d[1]:
break
else:
count += 1
if count == len(ignore_list):
return_list.append((d[0],d[1]))
return return_list
try:
new_functions = find_new_function(ignore_defs, defs)
def_name = new_functions[0][1]
except:
def_name = "DNE"
try:
function_above, distance = get_above_def(new_functions[0][0], defs)
except:
function_above = "DNE"
distance = "DNE"
try:
def_indent = t.get_indent_at_line(new_functions[0][0])
except:
def_indent = "DNE"
try:
text = docstrings[1][1]
text = text.replace(' ','').lower()
line_number = docstrings[1][0]
indent = t.get_indent_at_line(line_number)
except:
text = "DNE"
line_number == "DNE"
indent = "DNE"
try:
docstr_def, docstr_distance = get_above_def(line_number, defs)
except:
docstr_def = "DNE"
docstr_distance = "DNE"
t1 = TestObjective()
t1.add_success("add_player" in def_name, "Great job!")
t1.add_failure(def_name == "DNE", "Did you add Define Function?")
t1.add_failure("add_player" not in def_name and def_name != "DNE", "Did you rename the function to add_player()?")
t2 = TestObjective()
t2.add_success("set_stage" in function_above, "Great job!")
t2.add_failure("set_stage" not in function_above, "Did you place your new function under set_stage() and above main()?")
t2.add_failure(function_above == "", "Did you place add_player() below set_stage()?")
t3 = TestObjective()
t3.add_success(def_indent == 0, "Great job!")
t3.add_failure(def_indent > 0, "Make sure not to indent add_player() inside another function!")
t3.add_failure(def_indent == "DNE", "Did you add Define Function?")
t4 = TestObjective()
t4.add_success(num_docstrings > 2, "Great job!")
t4.add_failure(num_docstrings <= 2, "Did you add a Docstring under add_player()?")
t4.add_failure(num_docstrings == 0, "Oops. Did you delete a docstring?")
t5 = TestObjective()
t5.add_success(text != default_doc and num_docstrings > 2, "Great job!")
t5.add_failure(text == default_doc, "Did you change the docstring to describe the function?")
t5.add_failure(num_docstrings == 2, "Did you add a Docstring under add_player()?")
t6 = TestObjective()
t6.add_success(indent == 4 and num_docstrings > 2, "Great job!")
t6.add_failure(indent < 4, "Did you indent the docstring inside add_player()?")
t6.add_failure(indent > 4, "Oops, did you indent the docstring more than once?")
t6.add_failure(indent == "DNE", "Did you indent the docstring inside add_player()?")
t6.add_failure(num_docstrings == 2, "Did you add a Docstring under add_player()?")
t7 = TestObjective()
t7.add_success("add_player" in docstr_def and docstr_distance < 5, "Great job!")
t7.add_failure("add_player" not in docstr_def, "Did you place the docstring under add_player()?")
t7.add_failure(docstr_distance >= 5, "Make sure the docstring is at the top of the function!")
t7.add_failure(docstr_def == "DNE", "Did you delete a docstring?")
################################################
# Pass test code
# - set pass_required to True if pass is required
# - include tpass before t1 in the test list
pass_required = False
passes = t.find_text("pass")
num_pass_only = 0
for p in passes:
if p[1].lower().replace(' ','') == "pass":
num_pass_only += 1
tpass = TestObjective()
if not pass_required:
tpass.add_success(num_pass_only == 0, "Great job!")
tpass.add_creative(num_pass_only > 0, "Great job! Feel free to delete pass statements now.")
################################################
tester = TestManager()
tester.add_test_list([tpass, t1, t2, t3, t4, t5, t6, t7])
tester.run_tests()
tester.display_first_feedback()